home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / doors_1 / doorskl3.zip / DOORSKL2.C < prev    next >
C/C++ Source or Header  |  1991-12-05  |  8KB  |  302 lines

  1. /**********************************************/
  2. /*                                              */
  3. /* XBBS Door Skeleton -- TC 2.0/MSC 6.0a code */
  4. /* Copyright (c) 1990/91 by M. Kimes          */
  5. /* All Rights Reserved                        */
  6. /* May be freely used for >>>FREE<<< programs */
  7. /* as long as you don't try to save any souls */
  8. /* (nasty habit)                              */
  9. /*                                            */
  10. /**********************************************/
  11.  
  12. /* Always include this module (with appropriate #defines) */
  13.  
  14. /**************************************************************************
  15.   Miscellaneous notes:
  16.     #define XBBS and the program will be compiled to read ONLINE.XBS
  17.     #define DORINFO and the program will be compiled to read DORINFO?.DEF
  18.     #define both and first ONLINE.XBS will be read, then DORINFO?.DEF
  19.     #define neither and all info must come from command line
  20.     #define FINDUSER and a routine to find a given user (by name) will
  21.             be compiled in (finduser()) for XBBS' USERS.BBS
  22.     #define NOREADFILE and the file reader routine (readtext()) will NOT
  23.             be compiled
  24.     set chars to be unsigned by default
  25.     this code requires a FOSSIL for serial i/o--see function fossil()
  26. ***************************************************************************/
  27.  
  28. #include "doorskel.h"   /* XBBS Door include file */
  29.  
  30.  
  31.  
  32.  
  33.  
  34. #ifdef DORINFO
  35.  
  36. void _fastcall readinfo (void) {       /* Read DORINFO?.DEF */
  37.  
  38.     register int x;
  39.     FILE *fp;
  40.     char s[81];
  41.  
  42.  
  43.     sprintf(s,"DORINFO%hu.DEF",nodenumber);
  44.     if(!((fp = fopen(s,"rt")))) {
  45.         fputs("\nCouldn't open ",stdout);
  46.         fputs(s,stdout);
  47.         exit(253);
  48.     }
  49.     if(!fgets(s,81,fp)) goto EndIt;
  50.     stripcr(s);
  51.     s[63]=0;
  52.     strcpy(system_name,s);
  53.     if(!fgets(s,81,fp)) goto EndIt;
  54.     stripcr(s);
  55.     s[35]=0;
  56.     strcpy(sysop,s);
  57.     if(!fgets(s,81,fp)) goto EndIt;
  58.     stripcr(s);
  59.     s[35]=0;
  60.     x=strlen(sysop);
  61.     if(x<35) strcat(sysop," ");
  62.     if(x<36) strncat(sysop,s,36-x);
  63.     sysop[35]=0;
  64.     if(!fgets(s,81,fp)) goto EndIt;
  65.     if(atoi(&s[3])) commport=(char)atoi(&s[3]);
  66.     if(commport)commport--;
  67.     if(!fgets(s,81,fp)) goto EndIt;
  68.     baud=(word)atol(s);
  69.     if(!fgets(s,81,fp)) goto EndIt;
  70.     if(!fgets(s,81,fp)) goto EndIt;
  71.     stripcr(s);
  72.     s[35]=0;
  73.     strcpy(username,s);
  74.     if(!fgets(s,81,fp)) goto EndIt;
  75.     stripcr(s);
  76.     s[35]=0;
  77.     x=strlen(username);
  78.     if(x<35) strcat(username," ");
  79.     if(x<36)strncat(username,s,36-x);
  80.     if(!fgets(s,81,fp)) goto EndIt;
  81.     if(!fgets(s,81,fp)) goto EndIt;
  82.     if(atoi(s)) graphics=1;
  83.     if(!fgets(s,81,fp)) goto EndIt;
  84.     seclvl=(word)atol(s);
  85.     if(!fgets(s,81,fp)) goto EndIt;
  86.     timelimit = time(NULL) + (atol(s) * 60L);
  87. EndIt:
  88.     fclose(fp);
  89. }
  90.  
  91. #endif
  92.  
  93.  
  94. #ifdef FINDUSER
  95.  
  96. word _fastcall finduser (char *users_name,struct _user *other) {
  97.  
  98.     /* Finds user named users_name in users.bbs unless user isn't there
  99.        or user is locked out.  Returns user # and alters structure other
  100.        to contain user's info.  Info is undefined if 0 is returned. */
  101.  
  102.     FILE *fp;
  103.     int handle;
  104.     register word xx;
  105.     word tempuserno = 0;
  106.     struct stat f;
  107.  
  108.  
  109.     if(stat(searchpath("users.bbs"),&f)) {
  110.         printm("\r\nCan't find userfile.\r\n");
  111.         return 0;
  112.     }
  113.     printfm("\r\nSearching for %s...",users_name);
  114.     strupr(users_name);
  115.     xx=0;
  116.     if (!f.st_size) {
  117.         printm("\r\nNull-length userfile.\r\n");
  118.         return 0;
  119.     }
  120.     if ((handle = sopen(searchpath("USERS.BBS"),O_RDONLY | O_BINARY,SH_DENYNONE,S_IREAD))==-1) {
  121.         printm("\r\nError opening userfile\\rn");
  122.         return 0;
  123.     }
  124.     fp = fdopen(handle,"rb");
  125.     rewind(fp);
  126.     while (!feof(fp) && !ferror(fp)) {
  127.          xx++;
  128.          if (!(xx%50)) printm(".");
  129.          if (fread(other,sizeof(struct _user),1,fp)!=1) break;
  130.          if (!(stricmp(other->name,users_name)) && (!other->deleted)) break;
  131.          if (!(stricmp(other->handle,users_name)) && (!other->deleted)) break;
  132.     }
  133.     if (((stricmp(other->name,users_name)) &&
  134.          (stricmp(other->handle,users_name))) || (other->deleted))
  135.              goto NotFound;
  136.     if (!other->stat[0]) goto NotFound;
  137.     tempuserno = (word)(ftell(fp)/(long)sizeof(struct _user));
  138.     fclose(fp);
  139.     close(handle);
  140.  
  141.     if (!tempuserno) {
  142. NotFound:
  143.         fclose(fp);
  144.         close(handle);
  145.         printfm("\r\n%s not found.\r\n",users_name);
  146.         return 0;
  147.     }
  148.     return tempuserno;
  149. }
  150.  
  151. #endif
  152.  
  153.  
  154.  
  155. #ifdef XBBS
  156.  
  157. void _fastcall readconfig (void) {   /* Read CONFIG.BBS */
  158.  
  159.     FILE *fp;
  160.     char s[15];
  161.  
  162.     if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
  163.     else strcpy(s,"config.bbs");
  164.  
  165.     if(!(fp=fopen(s,"rb"))) {
  166. Fatal:
  167.         fputs("\nCouldn't open or read ",stdout);
  168.         fputs(s,stdout);
  169.        exit(253);
  170.     }
  171.     if (fread(&conf,sizeof(conf),1,fp)!=1) goto Fatal;
  172.     fclose(fp);
  173.     strcpy(system_name,conf.system);
  174.     strcpy(sysop,conf.sysop);
  175.     commport=conf.commport;
  176.     strcpy(logfile,conf.logfile);
  177.     sysopin=conf.sysopin;
  178.     fastANSI=conf.fastANSI;
  179.     videomethod=conf.dvideo;
  180. }
  181.  
  182.  
  183.  
  184. void _fastcall getonline (void) {   /* Read ONLINE.XBS */
  185.  
  186.   FILE *fp;
  187.   char s[90];
  188.   char numnode[4]="";
  189.   word tlmit;
  190.  
  191.  
  192.   if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
  193.   sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
  194.  
  195.   if (!((fp=fopen(s,"rb")))) {
  196.     fputs("\nCouldn't open ",stdout);
  197.     fputs(s,stdout);
  198.     exit(253);
  199.   }
  200.   else {
  201.       fread(&user,sizeof(struct _user),1,fp);
  202.       fread(&userno,sizeof(userno),1,fp);
  203.       fread(&tlmit,sizeof(tlmit),1,fp);
  204.       timelimit=time(NULL) + ((long)tlmit * 60L);
  205.       fread(&timeon,sizeof(timeon),1,fp);
  206.       fread(&starter,sizeof(starter),1,fp);
  207.       fread(&baud,sizeof(baud),1,fp);
  208.       fread(&pages,sizeof(pages),1,fp);
  209.       fread(&age,sizeof(age),1,fp);
  210.       fread(&timer_off,sizeof(timer_off),1,fp);
  211.       fread(&hold_time,sizeof(hold_time),1,fp);
  212.       fread(variable,(sizeof(variable[0])*10),1,fp);
  213.       fread(&mboard,sizeof(mboard),1,fp);
  214.       fread(&fboard,sizeof(fboard),1,fp);
  215.       if (fread(event,(sizeof(struct _events)*10),1,fp)<1) {
  216.         fputs("\nCame up short!\n",stdout);
  217.         goto FatalError;
  218.       }
  219.   }
  220.   if (ferror(fp)) {
  221. FatalError:
  222.         fputs("\nCouldn't read ",stdout);
  223.         fputs(s,stdout);
  224.         exit(253);
  225.          fclose(fp);
  226.          exit(253);
  227.    }
  228.    fclose(fp);
  229.    strcpy(username,user.name);
  230.    seclvl=user.stat[0];
  231.    width=user.width;
  232.    numlines=user.length;
  233.    graphics=user.graphics;
  234.    timelimit = time(NULL) + ((long)tlmit * 60L);
  235. }
  236.  
  237.  
  238.  
  239. void _fastcall prepare (void) {     /* Rewrite ONLINE.XBS */
  240.  
  241.     FILE *fp;
  242.     char s[90];
  243.     char numnode[4]="";
  244.     word tlmit;
  245.  
  246.  
  247.     if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
  248.     sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
  249.     if(!(fp=fopen(s,"wb"))) {
  250.         fputs("\n\04Couldn't open ",stdout);
  251.         fputs(s,stdout);
  252.         fputs(" for writing.\n",stdout);
  253.     }
  254.     else {
  255.         fwrite(&user,sizeof(struct _user),1,fp);
  256.         fwrite(&userno,sizeof(userno),1,fp);
  257.         tlmit=(word)((timelimit - time(NULL)) / 60L);
  258.         fwrite(&tlmit,sizeof(tlmit),1,fp);
  259.         fwrite(&timeon,sizeof(timeon),1,fp);
  260.         fwrite(&starter,sizeof(starter),1,fp);
  261.         fwrite(&baud,sizeof(baud),1,fp);
  262.         fwrite(&pages,sizeof(pages),1,fp);
  263.         fwrite(&age,sizeof(age),1,fp);
  264.         fwrite(&timer_off,sizeof(timer_off),1,fp);
  265.         fwrite(&hold_time,sizeof(hold_time),1,fp);
  266.         fwrite(variable,sizeof(variable[0]),10,fp);
  267.         fwrite(&mboard,sizeof(struct _mboard),1,fp);
  268.         fwrite(&fboard,sizeof(struct _fboard),1,fp);
  269.         fwrite(event,sizeof(struct _events),10,fp);
  270.         if (ferror(fp)) {
  271.             fputs("\n\04Error writing ",stdout);
  272.             fputs(s,stdout);
  273.             fputs(".\n",stdout);
  274.         }
  275.         fclose(fp);
  276.     }
  277. }
  278.  
  279.  
  280.  
  281. void _fastcall saveconfig (void) {  /* Rewrite CONFIG.BBS */
  282.  
  283.     FILE *fp;
  284.     char s[14];
  285.  
  286.  
  287.     if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
  288.     else strcpy(s,"config.bbs");
  289.  
  290.     if (!(fp = fopen(s,"wb"))) {
  291.         fputs("\n\04Error writing ",stdout);
  292.         fputs(s,stdout);
  293.         fputs(".\n",stdout);
  294.     }
  295.     else {
  296.         fwrite(&conf,sizeof(conf),1,fp);
  297.         fclose(fp);
  298.     }
  299. }
  300.  
  301. #endif
  302.